package com.example.broadcast.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.util.Log;

public class ShockReceiver extends BroadcastReceiver {
    public static final String SHOCK_ACTION="com.example.broadcast.shock";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("tang", "onReceive: ");
        if(intent!=null&& intent.getAction().equals(SHOCK_ACTION))
        {
            Log.d("tang", "onReceive: 震动了");
            //从系统服务中获取震动管理器
            Vibrator vb= (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            //命令震动管理器震动，参数为震动的毫秒数
            vb.vibrate(500);
        }
    }
}